from flask_wtf import FlaskForm
from flask_wtf.file import FileRequired
from wtforms import StringField, PasswordField, SelectField, SubmitField, TextAreaField, DateField, FileField
from wtforms.validators import DataRequired
from models import UserRole

class UserForm(FlaskForm):
    username = StringField('Username', validators=[DataRequired()])
    role = SelectField('Role', choices=[
        (UserRole.ADMIN, 'Admin'),
        (UserRole.EDITOR, 'Editor'),
        (UserRole.USER, 'User')
    ], validators=[DataRequired()])
    submit = SubmitField('Save')

class LoginForm(FlaskForm):
    username = StringField('Username', validators=[DataRequired()])
    password = PasswordField('Password', validators=[DataRequired()])
    submit = SubmitField('Login')

class RegisterForm(FlaskForm):
    username = StringField('Username', validators=[DataRequired()])
    password = PasswordField('Password', validators=[DataRequired()])
    role = SelectField('Role', choices=[
        (UserRole.ADMIN, 'Admin'),
        (UserRole.EDITOR, 'Editor'),
        (UserRole.USER, 'User')
    ], default=UserRole.USER)
    submit = SubmitField('Register')


class PenaltyForm(FlaskForm):
    site = StringField('Site')
    url = StringField('URL')
    title = StringField('Title')
    case_no = StringField('Case Number', validators=[DataRequired()])
    criminal_type = StringField('Criminal Type')
    criminal_content = TextAreaField('Criminal Content')
    penalty_basis = StringField('Penalty Basis')
    penalty_category = StringField('Penalty Category')
    penalty_content = StringField('Penalty Content')
    forfeit = StringField('Forfeit')
    confiscation = StringField('Confiscation')
    revoke_cert = StringField('Revoke Certificate')
    judge_date = DateField('Judge Date', validators=[DataRequired()])
    admin_org = StringField('Admin Organization')
    admin_org_code = StringField('Admin Organization Code')
    source_org = StringField('Source Organization')
    source_org_code = StringField('Source Organization Code')
    counterpart = StringField('Counterpart', validators=[DataRequired()])
    cp_type = StringField('Counterpart Type')
    soc_code = StringField('Social Credit Code')
    org_code = StringField('Organization Code')
    reg_code = StringField('Registration Code')
    tax_code = StringField('Tax Code')
    unit_code = StringField('Unit Code')
    org_reg_id = StringField('Organization Registration ID')
    legal_person = StringField('Legal Person')
    lp_cert_type = StringField('Legal Person Certificate Type')
    lp_cert_code = StringField('Legal Person Certificate Code')
    cert_type = StringField('Certificate Type')
    cert_code = StringField('Certificate Code')
    update_date = DateField('Update Date')
    content = TextAreaField('Content')
    note = TextAreaField('Note')
    status = StringField('Status')
    subject_1 = StringField('Subject 1')
    subject_2 = StringField('Subject 2')
    district = StringField('District')
    district_level = StringField('District Level')
    org_type = StringField('Organization Type')
    counterpart_type = StringField('Counterpart Type')
    penalty_org_type = StringField('Penalty Organization Type')
    penalty_person_type = StringField('Penalty Person Type')
    submit = SubmitField('Save')

class UploadForm(FlaskForm):
    file = FileField('Upload Excel File', validators=[FileRequired()])
    submit = SubmitField('Upload')